package app.blog.entity;

import slap.berkeleydb.BDB;
import app.blog.Blog;

import com.sleepycat.persist.PrimaryIndex;
import com.sleepycat.persist.SecondaryIndex;
import com.sleepycat.persist.model.DeleteAction;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;


@Entity
public class Comment {
	
	protected static PrimaryIndex<Integer, Comment> primaryIndex = 
		BDB.instanse(Blog.bdbName).getEntityStore().getPrimaryIndex(Integer.class, Comment.class);
	
	protected static SecondaryIndex<Integer, Integer, Comment> indexOnParent = 
		BDB.instanse(Blog.bdbName).getEntityStore().getSecondaryIndex(primaryIndex, Integer.class, "parent_id");
	
	public Article parent(){
		return Article.getById(parent_id);
	}
	
	@PrimaryKey(sequence = "comment-id")
	public Integer id;
	
	@SecondaryKey(
			relate = Relationship.MANY_TO_ONE, 
			relatedEntity = Category.class, 
			onRelatedEntityDelete = DeleteAction.CASCADE
	)
	public Integer parent_id;
	
	public String author_name;
	
	public String author_email;
	
	public String author_url;
	
	public String content;
	
}
